<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="#0A5AF9">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/public-head.css" />
    <link rel="stylesheet" type="text/css" href="../css/order-details.css" />
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
    <style>
        html,
        body {
            background-color: #FFFFFF;
        }

        * {
            margin: 0;
            padding: 0;
        }

    </style>
</head>

<body>
    <div class="main">
        <div id="pay_infor">
            <!-- <div class="zfcg">
          <img src="../image/icon/zhifcg-gx@2x.png" alt="" />
        </div>
        <div class="zfcg_text_1">支付成功</div>
        <div class="money">
          <div class="zfcg_text_2">￥<span>35.0</span></div>
        </div>
        <div class="list">
          <div class="list_1">
            <div>优惠券</div>
            <div>￥0</div>
          </div>
          <div class="list_1">
            <div>付款方式</div>
            <div>微信支付</div>
          </div>
          <div class="list_1">
            <div>下单时间</div>
            <div>2018-11-27 17:43</div>
          </div>
          <div class="list_1">
            <div>订单编号</div>
            <div>100023870087879</div>
          </div>
        </div> -->
        </div>
        <div class="gain-btn" id="gainBtn" tapmode onclick="fnCode()">
            <button>获取存钥密码</button>
        </div>
        <!--弹窗-->
        <div class="demo" id="pop">
            <div class='demo-bg'>
                <div class='demo-txt' tapmode onclick="closeDialog()">
                    <div class="indicating" onclick="window.close()">
                        <span>您的订单号:</span><img src="../image/icon/cdacha@2x0.png"/><br/>
                        <span style="font-size: 22px;font-weight: 500;" id="order">100023870087879028</span>
                        <span>已经预约成功,请尽快存入钥匙!</span>
                    </div>
                    <a href="mine_2.html"> — — — — — 存钥码 — — — — — </a>
                    <div class="number" id="number">
                        <div class="num"></div>
                       <div class="num"></div>
                       <div class="num"></div>
                       <div class="num"></div>
                       <div class="num"></div>
                       <div class="num"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

<script type="text/javascript" src="../script/rem.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/mui.js"></script>
<script type="text/javascript" src="../script/public-head.js"></script>
<script src="../script/template-web.js"></script>
<!-- 订单详细信息数据模型 -->
<script type="text/html" id="pay_infor_content">
    <div class="zfcg">
        <img src="../image/icon/zhifcg-gx@2x.png" alt="" />
    </div>
    <div class="zfcg_text_1">支付成功</div>
    <div class="money">
      {{if pay_price==undefined}}
      <div class="zfcg_text_2">￥<span>0</span></div>
      {{else}}
      <div class="zfcg_text_2">￥<span>{{pay_price}}</span></div>
      {{/if}}
    </div>
    <div class="list">
      {{if discount_price==undefined}}
        <div class="list_1" style="display:none">
            <div>优惠券</div>
            <div >￥0</div>
          </div>
            {{else}}
            <div class="list_1" style="display:none">
                <div>优惠券</div>
                <div >￥{{discount_price}}</div>
              </div>
            {{/if}}
        <div class="list_1">
            <div>付款方式</div>
            {{if payWay=="alipay"}}
            <div>支付宝支付</div>
            {{else if payWay=="wepay"}}
            <div>微信支付</div>
            {{else}}
            <div>使用优惠券</div>
            {{/if}}
        </div>
        <div class="list_1">
            <div>下单时间</div>
            <div>{{created_time}}</div>
        </div>
        <div class="list_1">
            <div>订单编号</div>
            <div>{{order_number}}</div>
        </div>
    </div>
</script>
<script type="text/javascript">
    apiready = function() {
     init();
     // 加载支付信息
     fnPay_infor();
     console.log(api.pageParam.order_number);
     console.log(api.pageParam.server_way);
     if( api.pageParam.server_way=="key"){
       $api.byId('gainBtn').style.display="block";
     }else{
       $api.byId('gainBtn').style.display="none";
     }

     exitHome();
    };
    headInner({
            title: "",
            //headleft
            headl: '<a href="#" style="color-btn:white"></a>',
            //headright
            headr: '<a style="color:white"><div style="color:#0A5AFA;font-size:15px;font-weight:500;margin-right:5px;" tapmode onclick="homepage_2()">完成</div></a>',
            color: "white", //默认是蓝色
            padding: "0px 0px 0px",
        })
        //弹窗 获取密码

    // 支付信息
    function fnPay_infor() {
        var infor_json = api.pageParam;
        console.log(api.pageParam.pay_price);
        console.log(JSON.stringify(api.pageParam));
        var html = template("pay_infor_content", infor_json);
        $api.byId('pay_infor').innerHTML = html;
    }

    function homepage_2() {
      api.closeToWin({
          name: 'Main_Frame'
      });

    }

    //返回主页
  	function exitHome() {
  		$api.setStorage('isHomeScreen', 0);
  		//按两次退出
  		api.addEventListener({
  			name: 'keyback'
  		}, function(ret, err) {
  			//全屏时 需要发送事件 并关闭全屏
  			var isHomeScreen = $api.getStorage('isHomeScreen');
  			console.log("isHomeScreen" + isHomeScreen);
  			//如果全屏 只关闭全屏
  			if (isHomeScreen == 0) {
  				api.toast({
  					msg: '再点一次返回主页',
  					duration: 2000,
  					location: 'bottom'
  				});
  				api.addEventListener({
  					name: 'keyback'
  				}, function(ret, err) {
  					if ($api.getStorage('isHomeScreen' == "0")) {
  						api.sendEvent({
  							name: 'clickhome',
  							extra: {}
  						});
  					} else {
  						api.closeToWin({
  						    name: 'Main_Frame'
  						});
  					}
  				});
  			}
  			setTimeout(function() {}, 2000)
  		});
  	}


    // 获取存钥码
    function fnCode() {
        BASE.MYajax({
            'pathName': 'keycabinet/getCode', //请求路径
            'methods': 'get',
            'ajaxData': {
                values: {
                    orders_id: api.pageParam.Orderid
                }
            },
            'method': codeData //调用函数
        });
    }
    function codeData(ret, err) {
        if (ret.code == 200) {
            console.log(JSON.stringify(ret))
             openDialog();
                //渲染取钥码
                $api.byId("order").innerHTML=api.pageParam.order_number;
                var number=document.getElementsByClassName("num")
             console.log(number.length);
               for (var i = 0; i < number.length; i++) {
                   number[i].innerHTML = ret.data.code[i];
               }
                console.log(JSON.stringify(ret));

        } else {
            alert(JSON.stringify(err));
        }
    }
    function openDialog() {
      var demobg=document.getElementsByClassName("demo-bg")[0]
        demobg.style.display = "block";
    }
    function closeDialog() {
      var demobg=document.getElementsByClassName("demo-bg")[0]
        demobg.style.display = "none";

    }

   //弹窗关闭

</script>

</html>
